package com.tron.dobest.elasticsearch;

import com.tron.dobest.mybatisplus.entity.Message;
import com.tron.dobest.mybatisplus.mapper.MessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 描述：测试配合elk时，数据库事务问题
 *
 * @author TRON
 * @since 2020-04-27
 */
@RestController
@Transactional
public class ElkController {
    @Autowired
    ElkDataRepository elkDataRepository;

    @Autowired
    MessageMapper messageMapper;



    @GetMapping("/elkTest")
    public Object elkTest() {
        ElkData elkData = new ElkData();
        Message message = new Message();
        message.setId("000000000012");
        elkData.setTime(11111L);
        elkData.setId("000000000012");
        elkData.setTitle("");
        int i = messageMapper.addMessage(message);
        System.out.println(i);
        if (i == 1) {
            ElkData save = elkDataRepository.save(elkData);
            throw new RuntimeException("全文检索保存失败");
        }
//        System.out.println(1/0);
        return elkData;
    }
}
